#define _CRT_SECURE_NO_WARNINGS 1
#include"twolist.h"

void Listprintf(sl* p)
{
	sl* q = p->next;
	while (q!=p)
	{
		printf("%d->", q->data);
		q = q->next;
	}
}

sl* ListInit()
{
	sl* w = (sl*)malloc(sizeof(sl));
	w->next = w;
	w->prev = w;
	return w;
}
void Listpushback(sl* p, Datatype x)
{
	assert(p);
	sl* tail = p->prev;
	sl* new = (sl*)malloc(sizeof(sl));
	new->data = x;
	tail->next = new;
	new->prev = tail;
	new->next = p;
	p->prev = new;
}
void Listpopback(sl* p)
{
	assert(p->next != p);
	/*sl* w = p->prev;
	sl* q = w->prev;
	p->prev = q;
	q->next = p;
	free(w);*/
	sl* w = p->prev;
	p->prev = w->prev;
	w->prev->next = p;
	free(w);
}

void Listpushfront(sl* p, Datatype x)
{
	sl* w = p->next;
	sl* T = (sl*)malloc(sizeof(sl));
	T->data = x;
	p->next = T;
	T->next = w;
	w->prev = T;
	T->prev = p;
}
void Listpopfront(sl* p)
{
	assert(p->next!=p);
	sl* t = p->next;
	p->next = t->next;
	t->next->prev = p;
	free(t);
}